const Koa  = require('koa')
const serve = require('koa-static');
const {historyApiFallback} = require('koa2-connect-history-api-fallback')
const proxy = require('koa2-proxy-middleware')

const app = new Koa();
app.use(historyApiFallback())
app.use(serve(__dirname + "/dist")); //将public下的代码静态化

app.listen(3333, () => {
     console.log('人资项目启动哦')
     console.log('http://localhost:3333')
})

// 处理api请求
app.use(proxy({
    targets: {
      '/prod-api/(.*)': {
        target: 'http://localhost:886',
        changeOrigin: true,
        // 如果前端考虑安全或其他原因, 故意
        // 用跟后台不一样的地址发送api 可以在这
        // 做路径重写
        pathRewrite: {
          '/prod-api': '/api'
        }
      }
    }
  }))